#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <math.h>
#include "rngs.h"
#include "testhelpers.c"

// tests fullDeckCount;

int main(){
    struct gameState *state = malloc(sizeof(struct gameState));
    int randomCount[treasure_map+1];
    int numTests = 50;
    int i;
    int random;
    int j;
    int card;

    setState(state);
    resetFlag();
    resetDeck(state);

    printf("Testing fullDeckCount\n");
    //default deck should have 3 estates and 10 copper  This is a very basic test
    if (fullDeckCount(0, estate, state)!= 3);

    if (fullDeckCount(0, copper, state) != 10);

    //constructs some random decks and verifies counts
    for(i = 0; i < numTests; i++){
        for (j = 0; j < treasure_map+1; j++){
            randomCount[j] = 0;
        }
        random = (int)(floor(Random()*250 + 1))/4;
        for (j = 0; j < random; j++){
            card=randomCard(state);
            state->deck[0][j+10] = card;
            state->deckCount[0]++;
            randomCount[card]++;
            card=randomCard(state);
            state->discard[0][j+10] = card;
            state->discardCount[0]++;
            randomCount[card]++;
            card=randomCard(state);
            state->hand[0][j+10] = card;
            state->handCount[0]++;
            randomCount[card]++;
            card=randomCard(state);
            state->playedCards[j+10] = card;
            state->playedCardCount++;
            randomCount[card]++;
        }
        for (j = 0; j < treasure_map + 1; j++){
            if(fullDeckCount(0, j, state)!= randomCount[j]){
                printf("fullDeckCount doesn't match manual count for card %d\n", j);
                printf("Count is %d, should be %d\n", fullDeckCount(0, j, state), randomCount[j]);
                incState();
            }
        }
    }

    if (testState() == 0){
        printf("Full Deck Count Test Passed\n");
    }
    else
        printf("Full Deck Count Test Failed\n");

    free(state);
    return 0;
}
